Skip to content

fix: support pagination and cwd filtering in list sessions#13460

Closed
aniruddhaadak80 wants to merge 1 commit intoNousResearch:mainfrom
aniruddhaadak80:fix-acp-sessions-cursor
Closed

fix: support pagination and cwd filtering in list sessions#13460
aniruddhaadak80 wants to merge 1 commit intoNousResearch:mainfrom
aniruddhaadak80:fix-acp-sessions-cursor

Conversation

@aniruddhaadak80
Copy link
Copy Markdown
Contributor

@aniruddhaadak80 aniruddhaadak80 commented Apr 21, 2026

Fixes Issue #13450. This commit adds cursor index tracking, limits, and nextCursor generation for the paginated ACP sessions list endpoint.

Copilot AI review requested due to automatic review settings April 21, 2026 10:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds pagination support to the ACP “list sessions” endpoint to address Issue 13450, enabling clients to page through session listings while still supporting cwd-based filtering via the SessionManager.

Changes:

  • Adds cursor handling to return sessions after a given session ID.
  • Adds limit support and computes nextCursor when more results are available.
  • Extends ListSessionsResponse to include the computed nextCursor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread acp_adapter/server.py
)
)
return ListSessionsResponse(sessions=sessions)

Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on the blank line after appending to sessions, which will show up in diffs and can trip linters. Consider removing the extra spaces.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread acp_adapter/server.py
Comment on lines 442 to +472
@@ -451,7 +467,9 @@ async def list_sessions(
updated_at=updated_at,
)
)
return ListSessionsResponse(sessions=sessions)

next_cursor = sessions[-1].session_id if has_more and sessions else None
return ListSessionsResponse(sessions=sessions, nextCursor=next_cursor)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pagination behavior (cursor slicing, limit, and nextCursor generation) is introduced here, but the existing ACP server tests only cover title/updated_at conversion and cwd filtering. Adding tests for: (1) limit truncation + nextCursor set, (2) passing cursor returns the next page, and (3) boundary cases like empty results would help prevent regressions.

Copilot uses AI. Check for mistakes.
Comment thread acp_adapter/server.py
infos = []

# Cap limit
limit = kwargs.get("limit", 50)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit is pulled from kwargs without validation/capping, despite the comment “Cap limit”. If the client passes a non-int (or a negative/zero) this can raise at len(infos) > limit / infos[:limit] or produce surprising pagination behavior. Consider coercing to int, defaulting on failure, and clamping to a sensible range (e.g., 1..1000).

Suggested change
limit = kwargs.get("limit", 50)
raw_limit = kwargs.get("limit", 50)
try:
limit = int(raw_limit)
except (TypeError, ValueError):
limit = 50
limit = max(1, min(limit, 1000))

Copilot uses AI. Check for mistakes.
Comment thread acp_adapter/server.py
Comment on lines +470 to +472

next_cursor = sessions[-1].session_id if has_more and sessions else None
return ListSessionsResponse(sessions=sessions, nextCursor=next_cursor)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ListSessionsResponse constructor is populated with nextCursor=... while the rest of this file consistently uses snake_case field names when instantiating ACP schema models (e.g., session_id=..., protocol_version=...). Even if aliases currently make this work, using the canonical Python field name here (likely next_cursor) would keep style consistent and reduce the chance of a runtime validation error if the schema config changes.

Suggested change
next_cursor = sessions[-1].session_id if has_more and sessions else None
return ListSessionsResponse(sessions=sessions, nextCursor=next_cursor)
next_cursor = sessions[-1].session_id if has_more and sessions else None
return ListSessionsResponse(sessions=sessions, next_cursor=next_cursor)

Copilot uses AI. Check for mistakes.
@teknium1
Copy link
Copy Markdown
Contributor

Salvaged via #13521 (merged). Your commit was cherry-picked onto current main and landed as c1fb7b6 with your authorship preserved — thanks for the fix!

Small follow-ups on top of your commit (in 4cc5065):

  • replaced kwargs.get('limit', 50) with a module-level _LIST_SESSIONS_PAGE_SIZE constant, since ListSessionsRequest has no limit field in the ACP schema
  • switched to the declared field name next_cursor= for consistency with the rest of the file
  • added 4 tests covering first-page pagination, single-page no-cursor, cursor resumes after match, and unknown cursor → empty

Closes #13450. Appreciate the contribution!

@teknium1 teknium1 closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants